<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./../../WEB-INF/templates/noFooterTemplate.xhtml">
            <ui:define name="content">
                <h:form id="viewAdminCandidateForm">
                    <p:growl id="growl"/>
                    <p:toolbar id="tb">  
                        <p:toolbarGroup align="left">  
                            <p:commandButton id="removeFilterButton" value="#{messages.CleanFilters}" onclick="candidatesTable.clearFilters()"/> 
                            <p:commandButton id="viewProfileButton" disabled="#{adminCandidateBean.chosenEntity==null}" value="#{messages.EditProfile}/ #{messages.ViewProfile}" action="#{adminEditCandidateBean.fillCandidateBean(adminCandidateBean.chosenEntity)}"/>
                            <p:commandButton id="removeProfileButton" disabled="#{adminCandidateBean.chosenEntity==null}" value="#{messages.RemoveProfile}" onclick="removeCandidateDialog.show()"> 
                            </p:commandButton>
                        </p:toolbarGroup>  
                    </p:toolbar> 
                    <p:panel id="candidatesDatatable" styleClass="noBorder noPadding noMargin">
                        <p:dataTable  var="candidate" value="#{adminCandidateBean.entityList}" rowKey="#{candidate.idCandidate}" selection="#{adminCandidateBean.chosenEntity}" selectionMode="single" filteredValue="#{adminCandidateBean.filteredEntitiesList}"
                                      paginator="true" rows="25" widgetVar="candidatesTable"
                                      paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                      rowsPerPageTemplate="25,50,100">  
                            <p:ajax event="rowSelect" update=":viewAdminCandidateForm:tb "/>
                            <p:ajax event="rowUnselect" update=":viewAdminCandidateForm:tb"/>
                            <ui:param name="Yes" value="#{messages.Yes}" />
                            <ui:param name="No" value="#{messages.No}" />
                            <p:column  headerText="#{messages.BustImageFileUploadLabel}" >  
                                <h:graphicImage styleClass="allWidth" value="/candidateFiles/#{candidate.idCandidate.toString()}/images/#{candidate.bustColor}" rendered="#{candidate.bustColor!=null}"/>  
                            </p:column> 
                            <p:column filterBy="#{candidate.name}" filterMatchMode="contains" sortBy="#{candidate.name}" headerText="#{messages.Name}">  
                                <h:outputText value="#{candidate.name}" />  
                            </p:column>  

                            <p:column filterBy="#{candidate.lastName}" filterMatchMode="contains" sortBy="#{candidate.lastName}" headerText="#{messages.LastName}">  
                                <h:outputText value="#{candidate.lastName}" />  
                            </p:column>  

                            <p:column filterBy="#{candidate.user.email}" filterMatchMode="contains" sortBy="#{candidate.user.email}" headerText="#{messages.Email}">  
                                <h:outputText value="#{candidate.user.email}" />  
                            </p:column>  

                            <p:column filterBy="#{candidate.phone}" filterMatchMode="contains" sortBy="#{candidate.phone}" headerText="#{messages.Phone}">  
                                <h:outputText value="#{candidate.phone}" />  
                            </p:column>
                            <p:column sortBy="#{candidate.birthDay}" headerText="#{messages.BirthDay}">  
                                <h:outputText value="#{candidate.birthDay}" rendered="#{candidate.birthDay!=null}">
                                    <f:convertDateTime pattern="d/M/yyyy"></f:convertDateTime>
                                </h:outputText>
                            </p:column> 
                            <p:column sortBy="#{candidate.user.creationDate}" headerText="#{messages.RegisterDate}">  
                                <h:outputText value="#{candidate.user.creationDate}">
                                    <f:convertDateTime pattern="d/M/yyyy - HH:mm"></f:convertDateTime>
                                </h:outputText>
                            </p:column> 
                            <p:column sortBy="#{candidate.user.lastDate}" headerText="#{messages.LastDate}">  
                                <h:outputText value="#{candidate.user.lastDate}">
                                    <f:convertDateTime pattern="d/M/yyyy - HH:mm"></f:convertDateTime>
                                </h:outputText>
                            </p:column> 
                            <p:column filterOptions="#{adminCandidateBean.trueFalseOptions}"  
                                      filterMatchMode="exact" filterBy="#{candidate.user.active}" sortBy="#{candidate.user.active}" headerText="#{messages.Active}">  
                                <h:outputText value="#{candidate.user.active == true ?Yes:No}" />   
                            </p:column>  
                            <p:column filterOptions="#{adminCandidateBean.trueFalseOptions}"  
                                      filterMatchMode="exact" filterBy="#{candidate.isValid}" sortBy="#{candidate.isValid}" headerText="#{messages.Valid}">  
                                <h:outputText value="#{candidate.isValid == true ?Yes:No}" />    
                            </p:column>
                            <p:column sortBy="#{candidate.user.logins}" headerText="#{messages.Logins}">  
                                <h:outputText value="#{candidate.user.logins}" />  
                            </p:column>
                        </p:dataTable>  
                    </p:panel>
                    <p:dialog modal="true" style="width:250px;" header="#{messages.AreYouSure}" resizable="false" id="removeCandidateDialog" widgetVar="removeCandidateDialog"  draggable="true" closable="true">  
                        <p:commandButton process="@this" value="#{messages.No}" onsuccess="removeCandidateDialog.hide();" update="removeCandidateDialog"/>  
                        <p:commandButton process="@parent" value="#{messages.Yes}" actionListener="#{adminCandidateBean.removeProfile()}" onsuccess="removeCandidateDialog.hide();" update=":viewAdminCandidateForm:candidatesDatatable removeCandidateDialog"/> 
                    </p:dialog> 
                </h:form>
            </ui:define>
        </ui:composition>

    </body>
</html>

